﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Runtime.InteropServices;
using WMPLib;
using System.Windows.Interop;

namespace XbdSoft.WPFVersion
{
    /// <summary>
    /// Interaction logic for TestWindpw.xaml
    /// </summary>
    public partial class TestWindow : Window
    {

        #region Set Window Long. Only run .NET 3.5. The reason hasn't been found

        private const int GWL_EXSTYLE = (-20);
        private const int GWL_STYLE = (-16);
        private const long WS_POPUP = 0x80000000L;
        private const long WS_CLIPCHILDREN = 0x02000000L;
        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        extern static int SetWindowLong(IntPtr hWnd, int nIndex, long dwNewLong);

        protected override void OnSourceInitialized(EventArgs e)
        {
            base.OnSourceInitialized(e);
            IntPtr hWnd = new WindowInteropHelper(this).Handle;
            SetWindowLong(hWnd);
        }

        private void SetWindowLong(IntPtr hWnd)
        {
            SetWindowLong(hWnd, GWL_EXSTYLE, WS_POPUP | WS_CLIPCHILDREN);
        }

        #endregion

        public TestWindow()
        {
            InitializeComponent();
            Loaded += new RoutedEventHandler(TestWindow_Loaded);
        }

        void TestWindow_Loaded(object sender, RoutedEventArgs e)
        {
            IntPtr hWnd = new System.Windows.Interop.WindowInteropHelper(this).Handle;
            SetWindowLong(hWnd);
            //McMediaElement.Source = new Uri("11.mp3",UriKind.Relative);//new Uri("http://www.xbd61.com/show_mp3.asp?S=9&ArticleID=294505");
            //McMediaElement.Play(); 
            //Background = new SolidColorBrush(Colors.Transparent);
            //IntPtr hWnd = new System.Windows.Interop.WindowInteropHelper(this).Handle;
            //SetWindowLong(hWnd, GWL_STYLE, WS_POPUP);
            //MainWebBrowser.Navigate(new Uri("http://www.google.com"));   
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            winMediaPlayer.Url = "http://www.xbd61.com/show_mp3.asp?S=9&ArticleID=294505";
            winMediaPlayer.Play();

        }
    }
}
